package com.xsjl.search.controller;


import com.xsjl.common.entity.PageResult;
import com.xsjl.common.entity.Result;
import com.xsjl.common.entity.StatusCode;
import com.xsjl.search.pojo.Article;
import com.xsjl.search.service.ArticleSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/article")
public class ArticleSearchController {
    @Autowired
    private ArticleSearchService searchService;

    @PostMapping
    public Result saveArticle(@RequestBody Article article) {
        searchService.save(article);
        return new Result(true, StatusCode.OK, "操作成功");
    }

    @RequestMapping(value = "/search/{keywords}/{page}/{size}", method = RequestMethod.GET)
    public Result findByTitleLike(@PathVariable String keywords, @PathVariable int page, @PathVariable int size) {
        Page<Article> result = searchService.findByTitleLike(keywords, page, size);
        return new Result(true, StatusCode.OK, "查询成功", new PageResult<Article>(result.getTotalElements(), result.getContent()));
    }

}
